use serde::Deserialize;

/// 土壤数据的实体结构
#[derive(Debug, Default)]
pub struct Soil {
    pub address: u32,
    //含水
    pub moisture: f32,
    //温度
    pub temperature: f32,
    //导电
    pub electrical: u32,
    //氮
    pub nitrogen: u32,
    //磷
    pub phosphorus: u32,
    //钾
    pub potassium: u32,
    //盐
    pub salinity: u32,
    //tds
    pub tds: u32,
}

impl Soil {
    pub fn new(address: u32) -> Self {
        Self {
            address,
            moisture: 0.0,
            temperature: 0.0,
            electrical: 0,
            nitrogen: 0,
            phosphorus: 0,
            potassium: 0,
            salinity: 0,
            tds: 0,
        }
    }
}

/// 天气数据的实体结构
#[derive(Debug, Default)]
pub struct Weather {
    //地址
    pub address: u32,
    //湿度
    pub humidity: f32,
    //温度
    pub temperature: f32,
    //噪音
    pub noise: f32,
    //pm 2.5
    pub pm25: u32,
    //pm 10
    pub pm10: u32,
}

/// 雨雪数据的实体结构
impl Weather {
    pub fn new(address: u32) -> Self {
        Self {
            address,
            humidity: 0.0,
            temperature: 0.0,
            noise: 0.0,
            pm25: 0,
            pm10: 0,
        }
    }
}

#[derive(Debug, Default)]
pub struct Sleet {
    //地址
    pub address: u32,
    //开关
    pub status: bool,
}

impl Sleet {
    pub fn new(address: u32) -> Self {
        Self { address, status: false }
    }
}

#[derive(Debug, Default, Deserialize)]
pub struct OperationOrder {
    //设备id
    pub id: i32,
    //操作
    pub operation: i32,
}

impl OperationOrder {
    pub fn new(device_id: i32, operation: i32) -> Self {
        Self { id: device_id, operation }
    }
}